home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DTP / DTP_TEX / H220.ZIP / ITRNS211.ZIP / SRC / ITRANS.H < prev    next >
C/C++ Source or Header  |  1991-11-28  |  13KB  |  397 lines

  1. #ifndef ITRANS_H
  2. #define ITRANS_H
  3.  
  4. /*
  5.  *========================================================================== 
  6.  * Copyright 1991 Avinash Chopde, All Rights Reserved.
  7.  *
  8.  * Permission to use, copy, modify and distribute this software and its
  9.  * documentation for any purpose is hereby granted without fee, provided that
  10.  * the above copyright notice appear in all copies and that both that
  11.  * copyright notice and this permission notice appear in supporting
  12.  * documentation, and that the name of Avinash Chopde not be used in
  13.  * advertising or publicity pertaining to distribution of the software
  14.  * without specific, written prior permission.
  15.  * Avinash Chopde makes no representations about the suitability of this
  16.  * software for any purpose.
  17.  * It is provided "as is" without express or implied warranty.
  18.  *
  19.  * AVINASH CHOPDE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  20.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  21.  * IN NO EVENT SHALL AVINASH CHOPDE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  23.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  24.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  25.  * OF THIS SOFTWARE.
  26.  *
  27.  * Author:  Avinash Chopde, 1991
  28.  *        C2 Colonial Drive #4, Andover, MA 01810, USA.
  29.  *
  30.  */
  31.  
  32. /* static char S_RCSID[] = "$Header: e:/itrans/src/rcs/itrans.h 1.10 91/11/28 20:38:42 avinash Exp $"; */
  33.  
  34. #include <stdio.h>
  35. #include "../version.h"
  36.  
  37. #if defined(MSDOS) || defined(sgi)
  38. /* actually, should be included in more places, but many systems
  39.  * are still missing this file...
  40.  */
  41. #include "stdlib.h"
  42. #endif
  43.  
  44. #ifdef SYSV
  45. #include <string.h>
  46. #else
  47. #include <strings.h>
  48. #endif
  49.  
  50. #ifdef sgi
  51. #include <malloc.h>
  52. #endif
  53.  
  54. #if defined(__STDC__) || (PROTO_C)
  55. #   define P(s)    s
  56. #else
  57. #   define P(s) ()
  58. #endif
  59.  
  60. #include <ctype.h>
  61. #define YYDEBUG 1
  62.  
  63. #include "imap.h"
  64.  
  65. #ifdef MSDOS
  66.  
  67. # define PATHSEP    ';'
  68. # define DIRSEP        '\\'
  69. # define PATH_MAX    256
  70.  
  71. #else
  72.  
  73. # include <pwd.h>
  74. # define PATHSEP    ':'
  75. # define DIRSEP        '/'
  76. # define PATH_MAX    1024
  77.  
  78. #endif
  79.  
  80. /* CONVWORD_LEN is the number of characters that will be generated
  81.  * (in TeX or in PostScript) when a single input word is converted
  82.  * Should be large enough to handle the verbose TeX commands,
  83.  * long words in indian languages....
  84.  */
  85. #define CONVWORD_LEN    8192
  86.  
  87. /* somewhere between Jan-July 1991, the first version of this
  88.  * software came out.
  89.  * Supported Devnagari only, under hindi/marathi switches.
  90.  */
  91.  
  92. /* environment variable for all the paths to search for input file.. */
  93. #define ITRANS_PATH    "ITRANSPATH"
  94. #ifdef MSDOS
  95. #define ITRANS_PATH_DEF    "ITRANSPATH=;..\\lib;"
  96. #else
  97. #define ITRANS_PATH_DEF    "ITRANSPATH=:../lib:"
  98. #endif
  99.  
  100. /* the default ifm file to use --- assume devanagari input */
  101. #define DEVN_IFM_FILE    "dvnc.ifm"
  102.  
  103. #define FALSE    0
  104. #define TRUE    1
  105.  
  106. #define NAMELEN        1024
  107. #define LANGS_MAX    (ENDLANG_TOK - ILANG_TOK)
  108. #define FONTS_MAX    (LANGS_MAX + 3)
  109.  
  110. #define LINELEN        1024
  111.     /* max input line len - AFM, IFM files, mainly */
  112.  
  113. #define    VOWEL_TYPE    1
  114. #define    CONSONANT_SINGLE_TYPE    2
  115. #define    CONSONANT_DOUBLE_TYPE    3
  116. #define    SPECIAL_TYPE    4
  117.  
  118. #define    CONSONANT_MANY_TYPE    100
  119. #define CONS_MAX    10
  120.     /* maximum number of (half) consonants allowed.
  121.      * each indian language letter is either a vowel or a
  122.      * list of half consonants followed by a vowel.
  123.      */
  124.  
  125. #define    _I_(ANY_TOK)    ((ANY_TOK)-OFFSET_TOK)
  126.     /* _I_ converts a token from the parser to its index in
  127.      * the 'font_t.enc[_I_()]' array.
  128.      */
  129.  
  130. #define _F_(ANY_TOK)    ((ANY_TOK)-OFFSET_TOK)
  131.     /* _F_ converts a token from the parser to its form in
  132.      * the 'font_t.khadi[someconsonant][_F_()]' array.
  133.      * Note that forms exist only for A_TOK to AHA_TOK.
  134.      * (additional forms exist, such as HALF_FORM which
  135.      * have no corresponding parser token)
  136.      */
  137.  
  138. #define    A_FORM        (_F_(A_TOK))
  139. #define    AA_FORM        (_F_(AA_TOK))
  140. #define    I_FORM        (_F_(I_TOK))
  141. #define    II_FORM        (_F_(II_TOK))
  142. #define    U_FORM        (_F_(U_TOK))
  143. #define    UU_FORM        (_F_(UU_TOK))
  144. #define    RI_FORM        (_F_(RI_TOK))
  145. #define    RII_FORM    (_F_(RII_TOK))
  146. #define    LI_FORM        (_F_(LI_TOK))
  147. #define    LII_FORM    (_F_(LII_TOK))
  148. #define    AY_FORM        (_F_(AY_TOK))
  149. #define    AAY_FORM    (_F_(AAY_TOK))
  150. #define    AI_FORM        (_F_(AI_TOK))
  151. #define    O_FORM        (_F_(O_TOK))
  152. #define    OO_FORM        (_F_(OO_TOK))
  153. #define    AU_FORM        (_F_(AU_TOK))
  154. #define    AM_FORM        (_F_(AM_TOK))
  155. #define    AHA_FORM    (_F_(AHA_TOK))
  156. #define    HALF_FORM    (AHA_FORM + 1)
  157. #define    IMPLICIT_FORM    (AHA_FORM + 2)
  158.  
  159. #define NUMFORMS    (AHA_FORM + 3)
  160.  
  161. /* =================================================================== */
  162. /* PostScript Stuff */
  163.  
  164. /* EMSIZE will be the current font size
  165.  * EM converts given em size to PostScript point size
  166.  */
  167. #define EMSIZE    "EMSIZE"
  168. #define EMTOPS    "EM"
  169.  
  170. /* =================================================================== */
  171. /* TeX Stuff */
  172.  
  173. /* nothing yet */
  174.  
  175. /* =================================================================== */
  176. /* LETTER_T */
  177. /* Used to pass info from the parser to the application routine */
  178.  
  179. typedef struct {
  180.     int        type; /* type - vowel, consonant, or
  181.                * half consonant and another consonant
  182.                */
  183.     int        cons[CONS_MAX];
  184.     char    nolig[CONS_MAX];
  185.             /* normally, cons[i] and cons[i+1] are checked
  186.              * for ligatures, and if one exists, it is used.
  187.              * But, if nolig[i] is TRUE, then no check
  188.              * is made for ligatures, cons[i] is printed
  189.              * using its half form.
  190.              * Naturally, this only applies if n >= 2
  191.              */
  192.     int        n; /* number of consonants in cons */
  193.     int        v;    /* vowel that goes with c1 or c2 - or is standalone */
  194. }   letter_t;
  195.  
  196. /* =================================================================== */
  197. /* PSCHAR_T */
  198. typedef struct {
  199.     /* all units are for a 1 point size char, times 1000 */
  200.     int w; /* char width */
  201.     int llx, lly, urx, ury; /* bounding box */
  202. } pschar_t;
  203.  
  204. /* =================================================================== */
  205. /* COMP_UNIT_T */
  206. /* Each Devnagari Character is a Composite Character.
  207.  * Each composite character is a list of <pcode, deltas> that
  208.  * specify printer the given postscript char pcode, at the given delta.
  209.  * pcode may be IMPLICIT_PSCHAR, implying that this composite char
  210.  * is a complex char (ex: half sa, half ta, yee), and need to get the
  211.  * implicit form the the char.
  212.  * Implicit forms of single chars are directly defined, for multiple
  213.  * forms (as in the above given example) need to compose together
  214.  * all half/implicit forms of the complex char.
  215.  */
  216.  
  217. #define    IMPLICIT_PSCHAR    -1
  218. #define    NO_PSCHAR    -2
  219.  
  220. #define DORG_LL        1
  221. #define DORG_CLR    2
  222.     /* the deltas in comp_unit_t may be specied with
  223.      * respect to the current char origin (DORG_LL), or wrt to the
  224.      * next char origin (DORG_CLR - current-lower-right)
  225.      */
  226.  
  227. typedef struct __comp_unit_t {
  228.     int u_pschar; /* the postscript character code */
  229.           /* may be IMPLICIT_PSCHAR, implies that the entire
  230.            * implicit letter has to be printed out at this
  231.            * point.
  232.            */
  233.     int deltax, deltay;   /* The offset that is to be used
  234.                * to print this character.
  235.                * The offset is wrt to the current position,
  236.                * depends on the value of the  variable dorg.
  237.                * (UNLIKE Adobe's Composite Character
  238.                * defn which is always from char origin)
  239.                * The delta's refer to a char 1 point
  240.                * in size, and the delta's are x1000.
  241.                * If u_pschar == NO_PSCHAR, then
  242.                * no char is printed, just this delta
  243.                * is applied.
  244.                */
  245.     int    dorg; /* specifies whether the offset is wrt current pos
  246.            * or wrt the origin of the character.
  247.            * Is usually DORG_CLR, i.e current pos.
  248.            */
  249.     struct __comp_unit_t* next; /* pointer to the next comp_unit.. */
  250. } comp_unit_t; 
  251.  
  252. int cus_to_ps P((comp_unit_t* cus, /* chain of PostScript Chars to output */
  253.           int fsize, /* font size being used for the chars */
  254.           char pscomm[])); /* the postscript commands returned here */
  255.  
  256. int cus_to_tex P((comp_unit_t* cus, /* chain of PostScript Chars to output */
  257.           int fsize, /* font size being used for the chars */
  258.           char pscomm[])); /* the TeX commands returned here */
  259.  
  260. /* =================================================================== */
  261. /* DCHAR_T */
  262.  
  263. typedef struct __dchar_t {
  264.     comp_unit_t**    cus; /* for every form, will allocate NUMFORMS */
  265.     struct __dchar_t*    same_as; /* cus not defined for this, use some
  266.                   * some other character's cus.
  267.                   */
  268. } dchar_t;
  269.  
  270. /* =================================================================== */
  271. /* following numbers are assigned to font_t.prop data variable */
  272. #define    UNDEF_FONT    0
  273. #define    PS_FONT        1 /* use this font for PostScript out only */
  274. #define    TEX_FONT    2 /* use this font for TeX out only */
  275. #define    TEX_PS_FONT    3 /* use this font for PostScript or TeX out */
  276.  
  277. /* FONT_T */
  278. typedef struct {
  279.  
  280.     int            prop; /* font property: Postscript only, TeX
  281.                        * only, both Tex  and PostScript, etc */
  282.  
  283.     ifm_enc_t        enc[NUMCHARS];
  284.     /* Every indian lang char token that is returned by the
  285.      * parser is associated with a name here:
  286.      * ex, A_TOK from the parser is named "a",
  287.      * GYA_TOK is named "gya", etc
  288.      * These names are used to get the khadi, ligatures, etc
  289.      * from the IFM file for every indian lang form.
  290.      */
  291.  
  292.     dchar_t        khadi[NUMKHADI];
  293.     /* the ka, kaa, ki, etc forms, incl vowels.
  294.      * Vowels have only one form - the "a" form (implicit char form).
  295.      * Most chars here have khadi[][].cus non-NULL, while
  296.      * khadi[][].same_as is NULL.
  297.      */
  298.  
  299.     dchar_t        ligatures[NUMCHARS][NUMCHARS];
  300.     /* if special chars exist for consonant-consonant pairs:
  301.      * da-da, dha-da, ta-ta, etc
  302.      * Most chars here have ligatures[][].cus NULL, while
  303.      * ligatures[][].same_as is non-NULL.
  304.      */
  305.  
  306.     dchar_t        digits[10]; /* the numbers (0..9) themselves */
  307.     /* Most chars here have digits[].cus non-NULL (use A_FORM), while
  308.      * digits[].same_as is NULL.
  309.      */
  310.  
  311.     pschar_t        psfm[NUMPSCHARS]; /* PostScript Font Metrics */    
  312.  
  313.     char        name[NAMELEN]; /* the font name */
  314.     char        fname[NAMELEN]; /* the ifm file name */
  315.     int            use_ligatures; /* boolean: used by iyacc.y, font.c */
  316.     int            fontno; /* font number - token returned by YACC */
  317. } font_t;
  318.  
  319. int fillup_font        P((font_t* font, char fname[]));
  320. void init_font        P((font_t* font));
  321. void dump_font        P((font_t* font, FILE* outfp));
  322. int decode_name        P((char inword[], int* l0, int *l1, int* form));
  323. int make_letter        P((font_t* fptr, /* the font data structure to use */
  324.         letter_t dlet, /* letter to convert  */
  325.         comp_unit_t pcus[], /* the comp units that make this
  326.                      * letter - all u_pschar are valid
  327.                      * PostScript codes, or NO_PSCHAR
  328.                      */
  329.         int    size_pcus, /* array size of ecus- number of elements */
  330.         int *ox, int *oy, /* the orgin of this letter */
  331.         int *width)); /* the width of this complete letter */
  332.  
  333. /* =================================================================== */
  334. /* LANG_T */
  335. typedef struct {
  336.     char*    curr_ifmname; /* the current IFM file name */
  337.     char*    curr_fontcmd; /* the current font command */
  338.     font_t*    curr_font; /* font metrics */
  339.     char*    name; /* language name */
  340.     int        langno; /* token returned by ilex.l */
  341. } lang_t;
  342.  
  343. void init_langs        P((lang_t* l, int num));
  344. void clear_lang        P((lang_t *l));
  345. void null_lang        P((lang_t *l));
  346.  
  347. /* =================================================================== */
  348. /* ALLFONTS_T */
  349. typedef font_t*    allfonts_t[FONTS_MAX];
  350.  
  351. font_t*    find_font    P((allfonts_t af, char fname[]));
  352. FILE*   search_fopen    P((char* path, char* fname, char *mode));
  353. int chk_ext        P((char *path, char *right_ext));
  354.  
  355. int setifm        P((int lang_tok, char ifmtok[]));
  356. int setfontcmd        P((int lang_tok, char fontcmd[]));
  357. int find_load_ifm    P((lang_t* l, allfonts_t allf, char ifmtok[]));
  358. void process_istart    P((int lang_tok));
  359. void process_iend();
  360.  
  361. /* ===================================================================== */
  362. #ifdef MSDOS
  363. extern char* yytext; /* for PC flex */
  364. #else
  365. extern char yytext[]; /* for UNIX lex */
  366. #endif
  367. extern int G_lineno;
  368. extern int G_verbose;
  369. extern font_t*    G_current_font;
  370. extern ifm_enc_t G_ifm_map[NUMCHARS];
  371. /* ===================================================================== */
  372. #ifndef PROTO_C
  373. /* 
  374.    Shouldn't really need these prototype defns, but...
  375.    don't know what to do with this, where does this go, ...... 
  376.    I hope that if the user sets PROTO_C in the Makefile, then there
  377.    is some other source of this defn, otherwise, try it here...
  378. */
  379. extern void* malloc    P((size_t size));
  380. extern char* getenv P((char*));
  381.    /* stdlib.h is missing on many systems, therefore, I don't
  382.     * want to include stdlib.h.
  383.     * since I use only this(these) functions, added
  384.     * it here specifically.
  385.     */
  386.  
  387. #endif
  388.  
  389. #ifdef MSDOS
  390. /* MSDOS is missing the getopt function, it is added in utils.c */
  391. extern int getopt    P((int argc, char* argv[], char* optstring));
  392. #endif
  393.  
  394. /* ===========================^ itrans.h ^============================== */
  395. #undef P
  396. #endif /* ITRANS_H */
  397.